package com.wlj.jpa.api;

import com.wlj.jpa.entity.Book;
import com.wlj.jpa.query.BookQuery;
import com.wlj.jpa.service.IBookQueryService;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "api/")
public class BookApi {

    @Resource
    private IBookQueryService bookQueryService;
 
    @GetMapping("/findBookNoQuery/{page}/{size}")
    public String findBookNoQuery(ModelMap modelMap, @PathVariable Integer page, @PathVariable Integer size){
        Page<Book> datas = bookQueryService.findBookNoCriteria(page, size);
        modelMap.addAttribute("datas", datas);
        return "index";
    }
 
    @RequestMapping(value = "/findBookQuery",method = {RequestMethod.GET,RequestMethod.POST})
    public String findBookQuery(ModelMap modelMap, Integer page,Integer size, BookQuery bookQuery){
        Page<Book> datas = bookQueryService.findBookCriteria(page, size,bookQuery);
        modelMap.addAttribute("datas", datas);
        return "page";
    }
}